import { Component, OnInit, Output, EventEmitter } from '@angular/core';

import { RemoveTableService } from '../../../../public/serve/remove-table/remove-table.service';
import { HintsService } from '../../../../public/serve/hints/hints.service';
import { InitService } from '../../../../public/serve/init/init.service';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import { Service } from '../../../../server/server';

import { appProductUrl } from '../../../product.url';
import { product } from '../../../product.data';
import {appSynonymUrl} from '../../../../synonym/synonym.url';


@Component({
	selector: 'app-product-indexing-task-content-refIndex',
	templateUrl: './product-indexing-task-content-refIndex.component.html'
})
export class ProductIndexingTaskContentRefIndexComponent implements OnInit {
	taskProductData: any;
	refIndexing: any;
	title: string;
	@Output() refIndexEvent = new EventEmitter<void>();

	constructor(public initService: InitService,
		private server: Service,
		private request: CudTableService,
		private hintsService: HintsService) { }

	ngOnInit() {
	}

	setRefIndexData(data, refIndexing) {
		this.taskProductData = data;
		this.refIndexing = refIndexing;
		if(refIndexing === 1) {
			this.title = '取消设为参考标引提示';
		}else if(refIndexing === 0) {
			this.title = '设为参考标引提示';
		}
	}

	/**
	 * 修改任务产品内容参考标引状态
	 */
	updateTaskProductRef() {
		let params = {
			token: product.retrieval.token,
			id: this.taskProductData.id,
			productId: this.taskProductData.productId,
			taskId: this.taskProductData.taskId,
			refIndexing: this.refIndexing,
			updateBy: this.server.getuserName()
		};
		this.request.postRequest(this.server.baseUrl +appProductUrl.updateTaskProductRef, params).then(res => {
			if (res.result_code == '0000') {
				this.refIndexEvent.emit();
			}
			this.hintsService.messages(res.message, res.result_code);
			return;
		}).catch((err: any) => {
			this.hintsService.messages('error', 'error');
			return;
		});
	}
}
